<!DOCTYPE html>
<html class="x-admin-sm">

<head>
	<meta charset="UTF-8">
	<title>电子学会比赛管理系统</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport"
	      content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
	<link rel="stylesheet" href="./css/font.css">
	<link rel="stylesheet" href="./css/xadmin.css">
	<link rel="stylesheet" type="text/css" href="./lib/formSelect/formSelects-v4.css"/>
	<script type="text/javascript" src="./js/abkj/match/api/itemdefine.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/matchtype.js"></script>
	<script type="text/javascript" src="./js/abkj/ext/matchExt.js"></script>
	<!-- 引入在线资源 -->
	<script src="http://gosspublic.alicdn.com/aliyun-oss-sdk-6.4.0.min.js"></script>
	<script type="text/javascript" src="./js/abkj/oss/app.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/zone.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/topic.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/grade.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/scheduleitem.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/scheduletype.js"></script>

	<script type="text/javascript" src="./js/abkj/fun_tool.js"></script>
	<script type="text/javascript" src="./js/abkj/slAjax.js"></script>
	<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="./js/xadmin.js"></script>
	<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
	<!--[if lt IE 9]>
	<script src="./js/html5.min.js"></script>
	<script src="./js/respond.min.js"></script>
	<![endif]--></head>

<body>
<div class="layui-fluid" id="app">
	<div class="layui-row">
		<!--初始化复制， 需要在form上写 lay-fiter-->
		<form class="layui-form" lay-filter="matchForm">
			<div class="layui-form-item">
				<label for="username" class="layui-form-label">
					<span class="x-red">*</span>主题</label>
				<div class="layui-input-inline">
					<input type="text" id="theme" placeholder="请输入赛项主题" name="theme" required="" lay-verify="required"
					       autocomplete="off" class="layui-input"></div>
			</div>
			<div class="layui-form-item layui-form-text">
				<label for="desc" class="layui-form-label"><span class="x-red">*</span>简介</label>
				<div class="layui-input-block">
					<textarea style="width: 30%" id="introduction" placeholder="请输入200字以内的赛项简介" id="desc" lay-verify="required" name="desc"
					          class="layui-textarea"></textarea>
				</div>
			</div>
			<div class="layui-form-item layui-form-text">
				<label for="desc" class="layui-form-label"><span class="x-red">*</span>赛区(多选)</label>
				<div class="layui-input-inline" style="width: 400px">
					<select name="status" xm-select="select1" lay-verify="required">
					</select>
				</div>
				<a href="javascript:;" onclick="xadmin.open('新增赛区', 'addDivision.html',400, 400)"
				   style="color: #01AAED;line-height: 36px;">新增赛区</a>
			</div>
			<div class="layui-form-item layui-form-text">
				<label for="desc" class="layui-form-label"><span class="x-red">*</span>宣传图片</label>
				<div class="layui-input-inline">
					<button type="button" id="test1"
					        style="width: 80px;height: 80px;background: #ffffff;border: 1px solid #999;border: 1px dashed #d9d9d9;background-color: #fafafa;">
						<i class="layui-icon layui-icon-add-1" style="font-size: 30px;"></i>
						<section>
							上传图片
						</section>
					</button>
					<div class="layui-upload-list">
						<section id="demo1" class="img" style="width: 270px; height: 150px;display: none; background-size: cover;"></section>
					</div>
					<section class="tips x-red">仅支持png格式，图片大小为270 * 150</section>
				</div>
			</div>
			<!-- oss图片上传插件 开始 -->
			<!--<div class="form-group">-->
			<!--<label>Select file</label>-->
			<!--<input type="file" id="file"/>-->
			<!--</div>-->
			<!--<div class="form-group">-->
			<!--<label>Store as</label>-->
			<!--<input type="text" class="form-control" id="object-key-file" value="object"/>-->
			<!--</div>-->
			<!--<div>-->
			<!--<input type="button" id="ossbutton2" value="UploadOSS"/>-->
			<!--</div>-->
			<br/>
			<div class="progress" style="display: none;">
				<div id="progress-bar"
				     class="progress-bar"
				     role="progressbar"
				     aria-valuenow="0"
				     aria-valuemin="0"
				     aria-valuemax="100" style="min-width: 2em;">
					0%
				</div>
			</div>
			<!-- 结束 -->
			<div class="layui-form-item layui-form-text">
				<label for="desc" class="layui-form-label"><span class="x-red">*</span>参赛形式</label>
				<div class="layui-input-inline">
					<select name="status" id="multiplayer" >
						<option value="">请选择</option>
						<option value="0">单人</option>
						<option value="1">组队</option>
					</select>
				</div>
			</div>

			<div class="layui-form-item">
				<label style="margin-left: 30px;">
					<span class="x-red">*</span>赛程时间(勾选需要的赛程)</label>
				<div style="display: block">
					<section id="schedule1">
						<section id="schedule_sec" style="margin: 15px 105px;margin-top: 25px;">
							<input id="schedule_checkbox" style="margin-top: 0" type="checkbox" name="schedule_checkbox" title="初赛" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="schedule1_start" id="schedule1_start"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="schedule1_end" id="schedule1_end"></div>
						</section>
						<section style="margin: 15px 105px;">
							比赛形式(勾选需要的赛程)
						</section>
						<section id="scheduleitem1" style="margin: 15px 105px;">
							<input id="itemsel"   style="margin-top: 0" type="checkbox" name="itemsel" title="在线答题" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="scheduleitem1_start" id="start11"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="scheduleitem1_end" id="end11"></div>
						</section>
						<section id="scheduleitem2" style="margin: 15px 105px;">
							<input id="itemsel" style="margin-top: 0" type="checkbox" name="itemsel" title="提交作品" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="start" id="start12"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="end" id="end12"></div>
						</section>
						<section id="scheduleitem4" style="margin: 15px 105px;">
							<input id="itemsel" style="margin-top: 0" type="checkbox" name="itemsel" title="编程作品" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="start" id="start14"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="end" id="end14"></div>
						</section>
						<section id="scheduleitem3" style="margin: 15px 105px;">
							<input id="itemsel" style="margin-top: 0" type="checkbox" name="itemsel" title="现场比赛" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="start" id="start13"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="end" id="end13"></div>
						</section>
					</section>
					<section id="schedule2">
						<section id="schedule_sec" style="margin: 15px 105px;margin-top: 25px;">
							<input id="schedule_checkbox" style="margin-top: 0" type="checkbox" name="schedule_checkbox" title="复赛" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="start" id="schedule2_start"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="end" id="schedule2_end"></div>
						</section>
						<section style="margin: 15px 105px;">
							比赛形式(勾选需要的赛程)
						</section>
						<section id="scheduleitem1" style="margin: 15px 105px;">
							<input id="itemsel" style="margin-top: 0" type="checkbox" name="itemsel" title="在线答题" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="start" id="start21"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="end" id="end21"></div>
						</section>

						<section id="scheduleitem2" style="margin: 15px 105px;">
							<input id="itemsel" style="margin-top: 0" type="checkbox" name="itemsel" title="提交作品" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="start" id="start22"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="end" id="end22"></div>
						</section>
						<section id="scheduleitem4" style="margin: 15px 105px;">
							<input id="itemsel" style="margin-top: 0" type="checkbox" name="itemsel" title="编程作品" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="start" id="start24"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="end" id="end24"></div>
						</section>
						<section id="scheduleitem3" style="margin: 15px 105px;">
							<input id="itemsel" style="margin-top: 0" type="checkbox" name="itemsel" title="现场比赛" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="start" id="start23"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="end" id="end23"></div>
						</section>
					</section>

					<!-- </section> -->
					<section id="schedule3">
						<section id="schedule_sec" style="margin: 15px 105px;margin-top: 25px;">
							<input id="schedule_checkbox" style="margin-top: 0" type="checkbox" name="schedule_checkbox" title="决赛" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="start" id="schedule3_start"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="end" id="schedule3_end"></div>
						</section>
						<section style="margin: 15px 105px;">
							比赛形式(勾选需要的赛程)
						</section>
						<section id="scheduleitem1" style="margin: 15px 105px;">
							<input id="itemsel" style="margin-top: 0" type="checkbox" name="itemsel" title="在线答题" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="start" id="start31"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="end" id="end31"></div>
						</section>

						<section id="scheduleitem2" style="margin: 15px 105px;">
							<input id="itemsel" style="margin-top: 0" type="checkbox" name="itemsel" title="提交作品" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="start" id="start32"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="end" id="end32"></div>
						</section>
						<section id="scheduleitem4" style="margin: 15px 105px;">
							<input id="itemsel" style="margin-top: 0" type="checkbox" name="itemsel" title="编程作品" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="start" id="start34"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="end" id="end34"></div>
						</section>
						<section id="scheduleitem3" style="margin: 15px 105px;">
							<input id="itemsel" style="margin-top: 0" type="checkbox" name="itemsel" title="现场比赛" lay-skin="primary">
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="开始时间" name="start" id="start33"></div>
							<div class="layui-inline layui-show-xs-block" style="margin-bottom: 0">
								<input class="layui-input" autocomplete="off" placeholder="结束时间" name="end" id="end33"></div>
						</section>
					</section>
				</div>
			</div>

			<div class="layui-form-item layui-form-text">
				<label for="desc" class="layui-form-label"><span class="x-red"></span>赛项分类</label>
				<div class="layui-input-inline">
					<select name="status" lay-verify="required" id="selectMatchType">

					</select>
				</div>
			</div>

			<div class="layui-form-item layui-form-text">
				<label for="desc" class="layui-form-label"><span class="x-red">*</span>组别</label>
				<div class="layui-input-inline" id="graderoot">
					<input v-for="grade in gradeList" type="checkbox" name="mygrade" :title="grade.gradeName" lay-skin="primary" checked>

				</div>
			</div>

			<div class="layui-form-item layui-form-text">
				<label for="desc" class="layui-form-label" style="width: 105px;"><span class="x-red">*</span>初赛参赛者须知</label>
				<div class="layui-input-inline">
          <textarea class="layui-textarea" id="LAY_demo1" style="display: none">

					</textarea>
				</div>
			</div>
			<div class="layui-form-item layui-form-text">
				<label for="desc" class="layui-form-label" style="width: 105px;"><span class="x-red">*</span>复赛赛参赛者须知</label>
				<div class="layui-input-inline">
          <textarea class="layui-textarea" id="LAY_demo2" style="display: none">

					</textarea>
				</div>
			</div>
			<div class="layui-form-item layui-form-text">
				<label for="desc" class="layui-form-label" style="width: 105px;"><span class="x-red">*</span>决赛参赛者须知</label>
				<div class="layui-input-inline">
            <textarea class="layui-textarea" id="LAY_demo3" style="display: none">

						</textarea>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label"></label>
				<button class="layui-btn" lay-filter="add" id="add" lay-submit="">确认提交</button>
			</div>
		</form>
	</div>
</div>
<script src="./lib/formSelect/formSelects-v4.min.js" type="text/javascript" charset="utf-8"></script>
<script src="./js/vue.js"></script>
<script src="./js/jquery.min.js"></script>
<script>
var form
Date.prototype.Format = function(fmt)
	{ //author: meizz
		var o = {
			"M+" : this.getMonth()+1,                 //月份
			"d+" : this.getDate(),                    //日
			"h+" : this.getHours(),                   //小时
			"m+" : this.getMinutes(),                 //分
			"s+" : this.getSeconds(),                 //秒
			"q+" : Math.floor((this.getMonth()+3)/3), //季度
			"S"  : this.getMilliseconds()             //毫秒
		};
		if(/(y+)/.test(fmt))
			fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
		for(var k in o)
			if(new RegExp("("+ k +")").test(fmt))
		fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
		return fmt;
	}
var varOssImgUrl = ''
// oss 图片上传事件
document.getElementById('ossbutton2').onclick = function () {
	applyTokenDo(function (ret) {
		varOssImgUrl = 'https://dzxh.oss-cn-hangzhou.aliyuncs.com/' + ret.name

	}, function (ret) {

	})
}

function initSchduleItem(varRoot, varScheduleID, varItemId) {
	var varSchedule = varRoot.find('#scheduleitem' + varItemId)
	var varIsSel = varSchedule.find('#itemsel').is(':checked')
	if (!varIsSel)
		return null
	var varItemObj = {
		itemId: varItemId,
		id:'',
		itemName: varSchedule.find('#itemsel').attr('title'),
		startTime: toTime(varSchedule.find('#start' + varScheduleID + varItemId).val()) ,
		endTime: toTime(varSchedule.find('#end' + varScheduleID + varItemId).val())
	}
	return varItemObj
}
function toTime(strTime) {
 if (!strTime) {
    return '';
 }
 var myDate = new Date(strTime + '+0800');
 if (myDate == 'Invalid Date') {
  strTime = strTime.replace(/T/g, ' ');
  strTime = strTime.replace(/-/g, '/');
  strTime = strTime.replace(/\.\d+/, ' ');//去掉毫秒
  myDate = new Date(strTime + '+0800');
 }
 return myDate; //输出的也是带T时间格式，但在安卓和ios上时间保持一致
}
function initSchedule(varID) {
	var varSchedule = $('#schedule' + varID).find('#schedule_sec')

	var varIsSel = varSchedule.find('#schedule_checkbox').is(':checked')
  if (varIsSel==false){
		return null
	}




	// var layedit = layui.layedit
	// var index = layedit.build("LAY_demo"+varID);

	var varSObj = {
		scheduleType: varID,
		scheduleName: varSchedule.find('#schedule_checkbox').attr('title'),
		startTime:toTime(varSchedule.find('#schedule' + varID + '_start').val()),
		endTime: toTime(varSchedule.find('#schedule' + varID + '_end').val()) ,
		notice: $('#LAY_demo' + varID).val(),
		//notice:layedit.getText(index),
		topicId: $('#selectTopic').val(),
		topicName: $('#selectTopic').find('option:selected').text()
	}

	// 对应 MatchScheduleReqParamVO
	var varScheduleReq = {
		schedule: varSObj,
		scheduleItem: []
	}
	for (var i = 1; i < 5; ++i) {
		var varItem = initSchduleItem($('#schedule' + varID), varID, i)
		if (varItem != null) {
			varScheduleReq.scheduleItem.push(varItem)
		}
	}
	// console.log(varScheduleReq)
	// alert(varScheduleReq)
	return varScheduleReq
}

function initMatchObj() {
	var matchObj = {
		theme: $('#theme').val(),
		type: $('#selectMatchType').val(),
		typeName: $('#selectMatchType').find('option:selected').text(),
		mainImg: varOssImgUrl,
		introduction: $('#introduction').val(),
		multiplayer: $('#multiplayer').val()
	}
	return matchObj
}
</script>
<script>
var tool = fun_tool()
var myshuju,myshuju1,myshuju2
var app = new Vue({
	el: '#app',
	data: {
		id: tool.getUrlParam('id'),
		ScheduleItem: 'ScheduleItem',
		scheduletypeList: [],
		gradeList: [],
		zoneList: [],
		topicList: [],
		matchTypeList: [],
		ItemDefine: [],
		relist:[],

	},
	mounted: function () {


	},
	methods: {
		loadGradeList: function () {
			GradequeryList({}, function (data) {
				app.gradeList = data
				for (var i = 0; i < data.length; ++i) {
					var varApStr = '<input type="checkbox" name="mygrade" title="' + data[i].gradeName + '" value="' + data[i].id +
						'" id="grade' + data[i].id + '" lay-skin="primary">'
					$('#graderoot').append(varApStr)
				}
				layui.use('form', function () {
					 form = layui.form //
					form.render()
				})
			}, function (status, message) {
				alert(message)
			})
		},
		loadZoneList: function () {
			ZonequeryList({}, function (data) {
				app.zoneList = data
				var formSelects = layui.formSelects
				var varArr = []
				for (var i = 0; i < data.length; ++i) {
					var arrItem = {
						name: data[i].zoneName,
						value: data[i].id
					}
					varArr.push(arrItem)
				}
				formSelects.data('select1', 'local', {
					arr: varArr
				})
			}, function (status, message) {
				alert(message)
			})
		},
		loadTopicList: function () {
			TopicqueryList({}, function (data) {
				app.topicList = data
				var varApStr = '<option value="">请选择</option>'
				$('#selectTopic').append(varApStr)
				for (var i = 0; i < data.length; ++i) {
					varApStr = '<option value="' + data[i].id + '">' + data[i].name + '</option>'
					$('#selectTopic').append(varApStr)
				}
				layui.use('form', function () {
					 form = layui.form //
					form.render()
				})
			}, function (status, message) {

			})
		},
		loadMatchType: function () {
			MatchTypequeryList({}, function (data) {
				app.matchTypeList = data
				var varApStr = '<option value="">请选择</option>'
				$('#selectMatchType').append(varApStr)
				for (var i = 0; i < data.length; ++i) {
					varApStr = '<option value="' + data[i].id + '">' + data[i].name + '</option>'
					$('#selectMatchType').append(varApStr)
				}
				layui.use('form', function () {
					 form = layui.form //
					form.render()
				})
			})
		},
		loadItemDefine: function () {
			ItemDefinequeryList({}, function (data) {
				app.ItemDefine = data
				console.log(data)
			})
		},
		loadScheduleType: function () {
			ScheduleTypequeryList({}, function (data) {
				app.scheduletypeList = data
			})
		},
		getData: function () {
			localStorage.isrecordid=0
			this.loadZoneList()
			this.loadGradeList()
			this.loadMatchType()
			this.loadTopicList()
			this.loadItemDefine()
			this.loadScheduleType()
			var vm = this
			layui.use('form', function () {
				vm.form = layui.form
				if (vm.id) {
					localStorage.isrecordid=vm.id

					getMatchEntiry(vm.id,function(data){

            app.relist=data
						//  alert(data.zoneList)
             var data1=data.zoneList
						 document.getElementById("theme").value=data.tmatch.theme
						 document.getElementById("introduction").value=data.tmatch.introduction
						 var img=data.tmatch.mainImg
						 var typeName=data.tmatch.typeName
						 var selectMatchType=document.getElementById("selectMatchType")
						 for (i=0;i<selectMatchType.options.length;i++){
							   if (selectMatchType.options[i].text==typeName){
									  selectMatchType.options[i].selected=true
								 }
						 }
						 var gradeList=data.gradeList
						 gradeList=gradeList.toString()
						//  alert(gradeList)
						 var gradeList1=document.getElementsByName("mygrade")
						//  alert(gradeList1.length)
						 for (i=0;i<gradeList1.length;i++){
							  //  alert(gradeList)
								//  alert(gradeList1[i].value)
							     if (gradeList.indexOf(gradeList1[i].value)>-1){
										 gradeList1[i].checked=true
									 }
						 }
						 layui.form.render('select');
						 layui.form.render('checkbox');


              var  multiplayer1=data.tmatch.multiplayer
							$('#demo1').show().css('background-image', 'url(' + img+ ')')

						 document.getElementById("demo1").style.display='block'
						 var multiplayer=document.getElementById("multiplayer")
						 var chedulesList=data.chedulesList
						 var schedule_checkbox=document.getElementsByName("schedule_checkbox")


						 for (i=0;i<chedulesList.length;i++){
                  if (chedulesList[i].schedule.scheduleName=='初赛'){
										schedule_checkbox[0].checked=true
										document.getElementById("schedule1_start").value=new Date(chedulesList[i].schedule.startTime).Format("yyyy-MM-dd hh:mm:ss")
										document.getElementById("schedule1_end").value=new Date(chedulesList[i].schedule.endTime).Format("yyyy-MM-dd hh:mm:ss")
										// alert(chedulesList[i].schedule.notice)
										 myshuju=chedulesList[i].schedule.notice


											layui.use('layedit', function () {
											 layedit = layui.layedit
												, $ = layui.jquery

											 //构建一个默认的编辑器

											 //构建一个默认的编辑器
												index = layedit.build('LAY_demo1')

											 bianjiqi=index

											 layedit.setContent(bianjiqi, myshuju, false);
											 //编辑器外部操作

											 // $('.site-demo-layedit').on('click', function () {
											 // 	var type = $(this).data('type');
											 // 	active[type] ? active[type].call(this) : '';
											 // });
											})



										layui.form.render('checkbox');


										for (j=0;j<chedulesList[i].scheduleItem.length;j++){
                       //
											 if (chedulesList[i].scheduleItem[j].itemName=='在线答题'){
												 document.getElementsByName("itemsel")[0].checked=true
												 document.getElementById("start11").value=new Date(chedulesList[i].scheduleItem[j].startTime).Format("yyyy-MM-dd hh:mm:ss")
												 document.getElementById("end11").value=new Date(chedulesList[i].scheduleItem[j].endTime).Format("yyyy-MM-dd hh:mm:ss")


											 }
											 else if (chedulesList[i].scheduleItem[j].itemName=='提交作品'){
												 document.getElementsByName("itemsel")[1].checked=true
												 document.getElementById("start12").value=new Date(chedulesList[i].scheduleItem[j].startTime).Format("yyyy-MM-dd hh:mm:ss")
												 document.getElementById("end12").value=new Date(chedulesList[i].scheduleItem[j].endTime).Format("yyyy-MM-dd hh:mm:ss")



											 }
											 else if (chedulesList[i].scheduleItem[j].itemName=='编程作品'){
												 document.getElementsByName("itemsel")[2].checked=true
												 document.getElementById("start14").value=new Date(chedulesList[i].scheduleItem[j].startTime).Format("yyyy-MM-dd hh:mm:ss")
												 document.getElementById("end14").value=new Date(chedulesList[i].scheduleItem[j].endTime).Format("yyyy-MM-dd hh:mm:ss")



											}
											 else if (chedulesList[i].scheduleItem[j].itemName=='现场比赛'){
												 document.getElementsByName("itemsel")[3].checked=true
												 document.getElementById("start13").value=new Date(chedulesList[i].scheduleItem[j].startTime).Format("yyyy-MM-dd hh:mm:ss")
												 document.getElementById("end13").value=new Date(chedulesList[i].scheduleItem[j].endTime).Format("yyyy-MM-dd hh:mm:ss")



											}


										}

									}
									else if (chedulesList[i].schedule.scheduleName=='复赛'){
										schedule_checkbox[1].checked=true
										document.getElementById("schedule2_start").value=new Date(chedulesList[i].schedule.startTime).Format("yyyy-MM-dd hh:mm:ss")
										document.getElementById("schedule2_end").value=new Date(chedulesList[i].schedule.endTime).Format("yyyy-MM-dd hh:mm:ss")
										myshuju=chedulesList[i].schedule.notice


										 layui.use('layedit', function () {
											layedit = layui.layedit
											 , $ = layui.jquery

											//构建一个默认的编辑器

											//构建一个默认的编辑器

											index2 = layedit.build('LAY_demo2')


											 bianjiqi1=index2

											layedit.setContent(bianjiqi1, myshuju, false);
											//编辑器外部操作

											// $('.site-demo-layedit').on('click', function () {
											// 	var type = $(this).data('type');
											// 	active[type] ? active[type].call(this) : '';
											// });
										 })


										layui.form.render('checkbox');
										for (j=0;j<chedulesList[i].scheduleItem.length;j++){
                       //
											 if (chedulesList[i].scheduleItem[j].itemName=='在线答题'){
												 document.getElementsByName("itemsel")[4].checked=true
												 document.getElementById("start21").value=new Date(chedulesList[i].scheduleItem[j].startTime).Format("yyyy-MM-dd hh:mm:ss")
												 document.getElementById("end21").value=new Date(chedulesList[i].scheduleItem[j].endTime).Format("yyyy-MM-dd hh:mm:ss")



											 }
											 else if (chedulesList[i].scheduleItem[j].itemName=='提交作品'){
												 document.getElementsByName("itemsel")[5].checked=true
												 document.getElementById("start22").value=new Date(chedulesList[i].scheduleItem[j].startTime).Format("yyyy-MM-dd hh:mm:ss")
												document.getElementById("end22").value=new Date(chedulesList[i].scheduleItem[j].endTime).Format("yyyy-MM-dd hh:mm:ss")



											 }
											 else if (chedulesList[i].scheduleItem[j].itemName=='编程作品'){
												 document.getElementsByName("itemsel")[6].checked=true
												 document.getElementById("start24").value=new Date(chedulesList[i].scheduleItem[j].startTime).Format("yyyy-MM-dd hh:mm:ss")
												 document.getElementById("end24").value=new Date(chedulesList[i].scheduleItem[j].endTime).Format("yyyy-MM-dd hh:mm:ss")




											}
											 else if (chedulesList[i].scheduleItem[j].itemName=='现场比赛'){
												 document.getElementsByName("itemsel")[7].checked=true
												 document.getElementById("start23").value=new Date(chedulesList[i].scheduleItem[j].startTime).Format("yyyy-MM-dd hh:mm:ss")
												document.getElementById("end23").value=new Date(chedulesList[i].scheduleItem[j].endTime).Format("yyyy-MM-dd hh:mm:ss")




											}
											layui.form.render('checkbox');

										}



									}
									else if (chedulesList[i].schedule.scheduleName=='决赛'){
										schedule_checkbox[2].checked=true
										document.getElementById("schedule3_start").value=new Date(chedulesList[i].schedule.startTime).Format("yyyy-MM-dd hh:mm:ss")
										document.getElementById("schedule3_end").value=new Date(chedulesList[i].schedule.endTime).Format("yyyy-MM-dd hh:mm:ss")
										myshuju=chedulesList[i].schedule.notice


										 layui.use('layedit', function () {
											layedit = layui.layedit
											 , $ = layui.jquery

											//构建一个默认的编辑器

											//构建一个默认的编辑器

											 index3 = layedit.build('LAY_demo3')

											bianjiqi2=index3
											layedit.setContent(bianjiqi2, myshuju, false);
											//编辑器外部操作

											// $('.site-demo-layedit').on('click', function () {
											// 	var type = $(this).data('type');
											// 	active[type] ? active[type].call(this) : '';
											// });
										 })


										layui.form.render('checkbox');
										for (j=0;j<chedulesList[i].scheduleItem.length;j++){
                       //
											//  alert(chedulesList[i].scheduleItem[j].itemName)
											 if (chedulesList[i].scheduleItem[j].itemName=='在线答题'){
												 document.getElementsByName("itemsel")[8].checked=true
												 document.getElementById("start31").value=new Date(chedulesList[i].scheduleItem[j].startTime).Format("yyyy-MM-dd hh:mm:ss")
												document.getElementById("end31").value=new Date(chedulesList[i].scheduleItem[j].endTime).Format("yyyy-MM-dd hh:mm:ss")




											 }
											 else if (chedulesList[i].scheduleItem[j].itemName=='提交作品'){
												 document.getElementsByName("itemsel")[9].checked=true
												 document.getElementById("start32").value=new Date(chedulesList[i].scheduleItem[j].startTime).Format("yyyy-MM-dd hh:mm:ss")
											 document.getElementById("end32").value=new Date(chedulesList[i].scheduleItem[j].endTime).Format("yyyy-MM-dd hh:mm:ss")



											 }
											 else if (chedulesList[i].scheduleItem[j].itemName=='编程作品'){
												 document.getElementsByName("itemsel")[10].checked=true
												 document.getElementById("start34").value=new Date(chedulesList[i].scheduleItem[j].startTime).Format("yyyy-MM-dd hh:mm:ss")
											 document.getElementById("end34").value=new Date(chedulesList[i].scheduleItem[j].endTime).Format("yyyy-MM-dd hh:mm:ss")



											}
											 else if (chedulesList[i].scheduleItem[j].itemName=='现场比赛'){
												 document.getElementsByName("itemsel")[11].checked=true
												 document.getElementById("start33").value=new Date(chedulesList[i].scheduleItem[j].startTime).Format("yyyy-MM-dd hh:mm:ss")
											 document.getElementById("end33").value=new Date(chedulesList[i].scheduleItem[j].endTime).Format("yyyy-MM-dd hh:mm:ss")



											}
											layui.form.render('checkbox');

										}

									}
						 }
						//  alert(multiplayer.options.length)
						 for (i=0;i<multiplayer.options.length;i++){
                   var multiplayer2=parseInt(multiplayer.options[i].value)
									//  alert(multiplayer2)
                 if (multiplayer2==multiplayer1){
									//  alert("chenggong")
									 multiplayer.options[i].selected=true
									 break
								 }
						 }
						 layui.form.render('select');



						 var formSelects = layui.formSelects
						 setTimeout(function(){
							 var varArr = []
							 data=app.zoneList
							//  alert(JSON.stringify(data))
							//  alert(JSON.stringify(data1))
							//  alert(data1.length)
			 				for (var i = 0; i < data.length; ++i) {
								var arrItem = {
			 						name: data[i].zoneName,
			 						value: data[i].id,
									selected:false
			 					}
								   for (j=0;j<data1.length;j++){
										   if (data1[j]==data[i].id){
												 var arrItem = {
													 name: data[i].zoneName,
													 value: data[i].id,
													 selected:true
												 }
												 break;
											 }
									 }

			 					varArr.push(arrItem)
			 				}
			 				formSelects.data('select1', 'local', {
			 					arr: varArr
			 				})
							form.render()

						 },1000)

					},function(status,message){

					})
					// 如果进来有id， 即为编辑操作， form.val赋值， 第一个参数是form 身上的lay-filter参数， {表单每一项的name: value}

				}
					})
		}
	}
})
window.onload = function () {
	app.getData()
}

</script>
<script>
var bianjiqi
var bianjiqi1
var bianjiqi2
var layedit

layui.use('layedit', function () {
	layedit = layui.layedit
	 , $ = layui.jquery
	 layedit = layui.layedit
		, $ = layui.jquery
		layedit.set({
	uploadImage:{
	url:"http://47.114.219.249:88/abkj-api-auth-provider/login/putfile",//接口url
	type:'post'//默认post
}
});

 //构建一个默认的编辑器

	//构建一个默认的编辑器
	 index = layedit.build('LAY_demo1')
	index2 = layedit.build('LAY_demo2')
  index3 = layedit.build('LAY_demo3')
	bianjiqi=index
  bianjiqi1=index2
	bianjiqi2=index3
	//编辑器外部操作

	// $('.site-demo-layedit').on('click', function () {
	// 	var type = $(this).data('type');
	// 	active[type] ? active[type].call(this) : '';
	// });
})
layui.use('upload', function () {
	var $ = layui.jquery
		, upload = layui.upload

	//普通图片上传
	var uploadInst = upload.render({
		elem: '#test1',
		auto: false,
		// multiple: true,
		acceptMime: 'image/png',
		choose: function (obj) {
			//预读本地文件示例，不支持ie8
			obj.preview(function (index, file) {
				// console.log($('#test1'))
				// initSchedule(1);
				// initSchedule(2);
				// initSchedule(3);
				// var formSelects = layui.formSelects;
				// console.log(formSelects.value('select1', 'val'))
				// var selGrade=[]
				// for(var i=0;i<app.gradeList.length;++i){
				// 	var isCheck = $("#grade"+app.gradeList[i].id).is(":checked")
				// 	if(isCheck){
				// 		selGrade.push(app.gradeList[i].id)
				// 	}
				// }
				// console.log(selGrade)
				applyTokenDo(file, function (ret) {
					varOssImgUrl = 'https://dzxh.oss-cn-hangzhou.aliyuncs.com/' + ret.name
					$('#demo1').show().css('background-image', 'url(' + varOssImgUrl + ')') //图片链接（base64）
				}, function (ret) {

				})

			})
		},
		error: function () {
			//演示失败状态，并实现重传
			var demoText = $('#demoText')
			demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>')
			demoText.find('.demo-reload').on('click', function () {
				uploadInst.upload()
			})
		}
	})
})

layui.use('laydate',
	function () {
		var laydate = layui.laydate
		for (var i = 1; i < 4; ++i) {
			//执行一个laydate实例
			laydate.render({
				elem: '#schedule' + i + '_start', //指定元素
				type: 'datetime',
        trigger: 'click'
			})
			laydate.render({
				elem: '#schedule' + i + '_end' ,
				type: 'datetime',
        trigger: 'click'
			})
			for (var t = 1; t < 5; ++t) {
				laydate.render({
					elem: '#start' + i + t,
					type: 'datetime',
	        trigger: 'click'
				})
				laydate.render({
					elem: '#end' + i + t ,
					type: 'datetime',
	        trigger: 'click'
				})
			}
		}
		//执行一个laydate实例
		laydate.render({
			elem: '#start',
			type: 'datetime',
			trigger: 'click'
		})

		laydate.render({
			elem: '#start1',
			type: 'datetime',
			trigger: 'click'
		})
		laydate.render({
			elem: '#start2' ,
			type: 'datetime',
			trigger: 'click'
		})
		//执行一个laydate实例
		laydate.render({
			elem: '#end' ,
			type: 'datetime',
			trigger: 'click'
		})
		laydate.render({
			elem: '#end1' ,
			type: 'datetime',
			trigger: 'click'
		})
		laydate.render({
			elem: '#end2' ,
			type: 'datetime',
			trigger: 'click'
		})

	})
layui.use(['form', 'layer'], function () {
		$ = layui.jquery
		 form = layui.form,
			layer = layui.layer

		//自定义验证规则
		// form.verify({
		// 	username: function (value) {
		// 		if (value.length < 5) {
		// 			return '主题至少得5个字符啊';
		// 		}
		// 	},
		// 	pass: [/(.+){6,12}$/, '密码必须6到12位'],
		// 	repass: function (value) {
		// 		if ($('#L_pass').val() != $('#L_repass').val()) {
		// 			return '两次密码不一致';
		// 		}
		// 	}
		// });

		//监听提交
		form.on('submit(add)',
			function (data) {
				// alert(JSON.stringify(data))
				//发异步，把数据提交给php
				var formSelects = layui.formSelects
				var reqParam = {
					zoneList: formSelects.value('select1', 'val'),
					gradeList: [],
					tmatch: {},
					chedulesList: []
				}
				reqParam.tmatch = initMatchObj()
				var selGrade = []
				for (var i = 0; i < app.gradeList.length; ++i) {
					var isCheck = $('#grade' + app.gradeList[i].id).is(':checked')
					if (isCheck) {
						selGrade.push(app.gradeList[i].id)
					}
				}
				reqParam.gradeList = selGrade
				for (var i = 1; i < 4; ++i) {
					var varItem = initSchedule(i)
					if (varItem != null) {
						reqParam.chedulesList.push(varItem)
					}
				}


				if (localStorage.isrecordid>0) {
					//修改
					var data=reqParam

					var data1=app.relist
				  data.tmatch.id=data1.tmatch.id
          try{
						for (i=0;i<data.chedulesList.length;i++){
							var list=data.chedulesList[i].scheduleItem
							for (j=0;j<data1.chedulesList.length;j++){
									   if (data.chedulesList[i].schedule.scheduleName==data1.chedulesList[j].schedule.scheduleName){
											 if (data.chedulesList[i].schedule.scheduleName=='初赛'){
                             data.chedulesList[i].schedule.notice=layedit.getContent(bianjiqi)
											 }
											 else if (data.chedulesList[i].schedule.scheduleName=='复赛'){
												 data.chedulesList[i].schedule.notice=layedit.getContent(bianjiqi1)

											 }
											 else if (data.chedulesList[i].schedule.scheduleName=='决赛'){
												data.chedulesList[i].schedule.notice=layedit.getContent(bianjiqi2)

											}
											 data.chedulesList[i].schedule.id=data1.chedulesList[j].schedule.id
											 data.chedulesList[i].schedule.matchId=data1.tmatch.id

											//  alert(JSON.stringify(data.chedulesList[i].scheduleItem))
											//  alert(JSON.stringify(data1.chedulesList[j].scheduleItem))
											 for (k=0;k<data.chedulesList[i].scheduleItem.length;k++){
												   for (t=0;t<data1.chedulesList[j].scheduleItem.length;t++){
														   if (data.chedulesList[i].scheduleItem[k].itemName==data1.chedulesList[j].scheduleItem[t].itemName){

																 data.chedulesList[i].scheduleItem[k].id=data1.chedulesList[j].scheduleItem[t].id
																 data.chedulesList[i].scheduleItem[k].scheduleId=data.chedulesList[i].schedule.id
																//  alert(data1.chedulesList[j].scheduleItem[t].id)
																 break
															 }
													 }

											 }
											// data.chedulesList[i].schedule.id=data1.chedulesList[j].schedule.id
											// var list1=data.chedulesList[j].scheduleItem


										 break
									 }
							}


						}
					}
					catch(error){

					}

        //
				  //  alert(JSON.stringify(reqParam))
					updateMatch(reqParam, function (data) {
						layer.alert('修改成功', {
								icon: 6
							},
							function () {
								// 获得frame索引

                     // alert(index)
                      //关闭当前frame
											var index = parent.layer.getFrameIndex(window.name)
											//关闭当前frame
											parent.layer.close(index)

											// 可以对父窗口进行刷新
											xadmin.father_reload()

							})
					})
				}
				else {
					addMatch(reqParam, function (data) {
						layer.alert('增加成功', {
								icon: 6
							},
							function () {
								// 获得frame索引
								var index = parent.layer.getFrameIndex(window.name)
								//关闭当前frame
								parent.layer.close(index)

								// 可以对父窗口进行刷新
								xadmin.father_reload()
							})
					})
				}


				return false
			})

	})</script>
<script>var _hmt = _hmt || [];
(function () {
	var hm = document.createElement('script')
	hm.src = 'https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190'
	var s = document.getElementsByTagName('script')[0]
	s.parentNode.insertBefore(hm, s)
})()</script>
</body>

</html>
